package com.bing.services.impl;

import com.bing.bean.sys.SysUser;
import com.bing.dao.SysUserDao;
import com.bing.services.SysUserService;
import com.bing.utils.Constant;
import org.apache.shiro.authc.credential.DefaultPasswordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2015/6/13.
 */
@Service
@Transactional
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserDao sysUserDao;
    @Autowired
    private DefaultPasswordService passwordService;
    private static final Logger logger = LoggerFactory.getLogger(SysUserServiceImpl.class);


    @Override
    public SysUser findByName(String name) {
        logger.info("查找用户:{}", name);
        return sysUserDao.findByName(name);
    }

    @Override
    public int createSysUser(SysUser user) {
        if (sysUserDao.findByName(user.getName()) != null) {
            logger.info("创建用户失败,己经存在此用户:{}", user.getName());
            return Constant.FAILED;
        }
        user.setPassword(passwordService.encryptPassword(user.getPassword()));
        return sysUserDao.createSysUser(user);
    }

    @Override
    public int updateSysUser(SysUser user) {
        return 0;
    }
}
